import QtQuick 1.1
import com.nokia.meego 1.1

Page {
    property bool empty: expenseList.count == 0
    tools: commonTools

    function del()
    {
        console.log("Deleting Expense")
    }
    function edit()
    {
        console.log("Editing Expense")
        if(myData.getExpense(expenseList.currentIndex))
            appWindow.pageStack.push(Qt.resolvedUrl("ExpenseEdit.qml"), {
                                                                    expns_id: expenseList.currentIndex,
                                                                    edit: true})
    }
    function add()
    {
        console.log("adding new Expense: " + expenseList.count)
        if(myData.newExpense())
            appWindow.pageStack.push(Qt.resolvedUrl("ExpenseEdit.qml"), {
                                                                    expns_id: expenseList.count,
                                                                    edit: false})
    }

    VisualDataModel {
        id: expenseModel

        model: myExpenses
    
        Component {
            id: expenseDelegate
            Item {
                width: parent.width
                height:child.height*1.2 
                anchors{leftMargin: 10; left:parent.left}
                Column {
                    id: child
                    width: parent.width
                    anchors.verticalCenter: parent.verticalCenter
                    spacing: 5
                    Label {
                        text: model.description; color: 'green'; font.pixelSize: 40;
                    }
                    Label {
                        text: model.timestamp + ': ' + model.amount + '@' + model.currency_rate + ' (' + myNames[model.account_id] + ')';
                        color: 'purple'; 
                    }
                }
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        expenseList.currentIndex = index
                    }
                }
            }
        }
    }
    ListView {
        id: expenseList
        anchors.fill: parent
        model: expenseModel
        highlight: Rectangle{width:parent.width; smooth:true; opacity:0.5; color: "darkslategrey"; radius: 10}
        focus: true
        spacing: 5
    }

}
